package com.xgq.drink.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xgq.drink.entity.Payment;
import com.xgq.drink.entity.R;
import com.xgq.drink.service.IPaymentService;
import com.xgq.drink.utils.RUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/payment")
@Tag(name = "支付模块(平台)", description = "支付相关接口（仅限后台管理员）")
public class PaymentController {

    @Autowired
    private IPaymentService paymentService;

    @GetMapping("/list")
    @Operation(summary = "分页查询支付记录", description = "后台管理员根据分页参数查询支付记录",
            responses = {
                    @ApiResponse(responseCode = "200", description = "查询成功",
                            content = @Content(schema = @Schema(implementation = List.class))),
                    @ApiResponse(responseCode = "400", description = "查询失败",
                            content = @Content(schema = @Schema(implementation = R.class)))
            })
    public R getPaymentList(@RequestParam(defaultValue = "1") int current,
                                           @RequestParam(defaultValue = "10") int size) {
        try {
            IPage<Payment> paymentList = paymentService.getPaymentList(current, size);
            return RUtils.success("查询成功", paymentList);
        } catch (Exception e) {
            return RUtils.fail("查询失败: " + e.getMessage());
        }
    }
}